<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends MY_Luckydog
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('luckydog/User_model', 'user');
        $login_status = $this->login_status = $this->check_login_status();
        if (empty($login_status)){
            redirect('/luckydog/login');
        }
    }



    public function index()
    {
        $_SESSION['v_menu'] = 'user';
        $starttime = $this->input->get("starttime",true)?$this->input->get("starttime",true):"";
        $endtime = $this->input->get("endtime",true)?$this->input->get("endtime",true):"";
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;
        $keyword = $this->input->get('keyword') ? $this->input->get('keyword') : "";
        $name = $this->input->get('name') ? $this->input->get('name') : "";
        $filter = array(
            'starttime'=>strtotime($starttime),
            'endtime'=>strtotime($endtime),
            'keyword'=>$keyword,
        );
		
        $limit = 20;
        $total_rows = $this->user->get_user_cnt($filter);
        $base_url = '/luckydog/user/index?';
        $page_links = $this->create_page_links($base_url,$total_rows,$limit);
        $userList = $this->user->userList($filter,$per_page,$limit);

        
        $data = array(
            'userList'=>$userList,
            'page_links'=>$page_links,
            'per_page'=>$per_page,
            'total_rows'=>$total_rows,
        );
        $this->load->view('/luckydog/user/user_list',$data);
    }  

    public function  textures()
    {
        $this->load->view("/luckydog/user/textures", $data);
    }
    public function editUser(){
        $AccountID = $this->input->post("AccountID",true) ? $this->input->post("AccountID",true) : 0;
        $username = $this->input->post("username",true) ? $this->input->post("username",true) : 0;
        $password = $this->input->post("password",true) ? $this->input->post("password",true) : 0;
        $departmentid = $this->input->post("departmentid",true) ? $this->input->post("departmentid",true) : 0;
        $truename = $this->input->post("truename",true) ? $this->input->post("truename",true) : 0;
        $data = [];
        $data['username']       =   $username;
        $data['password']       =   md6($password);
        $data['departmentid']   =   $departmentid;
        $data['truename']       =   $truename;
        if(empty($AccountID)){
            $data['addtime']    =time();    
        }
        $res = $this->user->editUser($AccountID, $data);
        echo $res;
    }
    /**
     *------------------------------------------------------------------------------------------------------------------
     * @title：编辑用户停用启用
     * @param：id      
     * @author:：柏凯
     * @date：2015-09-22
     *------------------------------------------------------------------------------------------------------------------
     */
    //设置角色启用状态
    public function editStatus(){
        $id = $this->input->post("id",true);
        $status = $this->input->post("status",true);
        $res = $this->user->editStatus($id,$status);
        echo $res;
    }

    
}
/* End of file user.php */
/* Location: ./application/controllers/luckydog/user.php */
